#ifndef CANVAS_H
#define CANVAS_H

#include <QWidget>
#include <QPointF>
#include <QPixmap>
#include <QPushButton>
#include <QComboBox>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QClipboard>

#include "rectpaint.h"
#include "linepaint.h"

enum DrawStatus{
    waitDraw=0,
    drawing,
    drew,
};

class Canvas : public QWidget
{
    Q_OBJECT
public:
    explicit Canvas(QWidget *parent = 0);

    void setbgPixmap(QPixmap &px);
    void shootScreen(QRectF &rect);

    void canvasInit();

    void initToolBar();
    void showToolBar();
    void hideToolBar();
    void refrashToolBar();
    quint8 caputerRect(QRectF t_rect,qreal t_x,qreal t_y);
    RectPaint getRectF(QPointF p1,QPointF p2);    //通过两个坐标点生成矩形
    void changeLanguage(QString lan);

signals:
    void sig_addWindow2Desktop(const QPixmap& pixmap);
public slots:
    void slt_drawLine();
    void slt_drawRect();
    void slt_drawEllipse();
    void slt_saveFile();            //保存到文件
    void slt_saveClipboard();       //保存到剪切板
    void slt_cancel();
    void slt_showOnDesktop();

    void slt_changePenWidth(QString s);
    void slt_changePenColor();
    void slt_changePenStyle(int index);

private:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void paintEvent(QPaintEvent *e);

private:
    int mScreen_width=0;
    int mScreen_height=0;
    quint8 mOkFlag=0;
    quint8 mCursorCaptureFlag=0;

    QPointF mPointS;     //鼠标绘制起点
    QPointF mPointE;     //鼠标绘制终点
    RectPaint mShotArea;    //截图区域

    QList<LinePaint> mLineList;         //直线列表
    QList<RectPaint> mRectList;         //矩形列表
    QList<RectPaint> mEllipseList;      //椭圆列表

    QPointF mPointDrag;     //拖拽点
    DrawStatus mDrawFlag=DrawStatus::waitDraw;
    quint8 mDrawEditFlag=0;  //绘图修改

    QPixmap mFullPixmap;         //原始全屏图片
    QPixmap mOriginalPixmap;

    QWidget *mpToolbar;           //工具条
    QPushButton *mpBtn_showOnDesktop;
    QPushButton *mpBtn_saveFile;
    QPushButton *mpBtn_saveClipboard;
    QPushButton *mpBtn_cancel;
    QPushButton *mpBtn_drawLine;      //画直线
    QPushButton *mpBtn_drawRect;      //画矩形
    QPushButton *mpBtn_drawEllipse;   //画椭圆

    QPen mDrawPen;                   //线宽颜色风格
    QWidget *mpShapeToolBar;
    QWidget *mpTextToolBar;

    QComboBox *mpCbx_lineSize;
    QPushButton *mpBtn_colorSelect;
    QComboBox *mpCbx_lineStyle;

    QClipboard *mpClipboard;
};

#endif // CANVAS_H
